<!DOCTYPE html>
<html class="loginHtml">
<head>
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="0">
	<meta charset="utf-8">
	<title>用户注册</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" href="/favicon.ico">
	<link rel="stylesheet" href="/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/css/public.css" media="all" />
	<link rel="stylesheet" href="/css/special.css" media="all" />
    <script type="text/javascript" src="/layui/layui.js"></script>
    <script type="text/javascript" src="/js/lib/md5.js"></script>
	<script type="text/javascript" src="/js/pages/customer.js"></script>
	<script type="text/javascript" src="/js/lib/jquery-1.10.1.min.js"></script>
</head>
<body>

<form id="agreement_trial" class="layui-form layui-row layui-col-space10 register-agreement-form dn" onkeydown="if(event.keyCode==13) return false;">
	<div class="layui-col-md12 layui-col-xs12">
		<div class="layui-form-item">
			<label class="layui-form-label">生日</label>
			<div class="layui-input-block">
				<input type="text" name="birthDay" placeholder="请输入出生年月" required readonly class="layui-input userBirthday">
			</div>
		</div>

		<input name="id" id="trialId" type="hidden"/>

		<div class="layui-form-item">
			<label class="layui-form-label">收件人</label>
			<div class="layui-input-block">
				<input type="text" name="receiver" required placeholder="请输入收件人" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">地址</label>
			<div class="layui-input-block">
				<input type="text" name="address" required placeholder="请输入地址" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">邮编</label>
			<div class="layui-input-block">
				<input type="text" name="emailCode" required  placeholder="请输入邮编" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">居留复印件</label>
			<div class="layui-input-block">
				<button type="button" class="layui-btn layui-btn-sm" id="residencePdfBtn" style="display: inline">
					<i class="layui-icon">&#xe67c;</i>上传居留复印件PDF
				</button>
				<input type="text" name="residencePdf" required readonly class="layui-input" style="display: inline;width: 400px;">
				<button type="button" class="layui-btn layui-btn-sm layui-btn-warm" onclick="openPdf( 'residencePdf');" style="display: inline">查看PDF</button>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">居留卡号</label>
			<div class="layui-input-block">
				<input type="text" name="residenceNo" required placeholder="请输入居留卡号" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">医保卡复印件</label>
			<div class="layui-input-block">
				<button type="button" class="layui-btn layui-btn-sm" id="insurancePdfBtn" style="display: inline">
					<i class="layui-icon">&#xe67c;</i>上传医保卡复印件PDF
				</button>
				<input type="text" name="insurancePdf" readonly class="layui-input" style="display: inline;width: 400px;">
				<button type="button" class="layui-btn layui-btn-sm layui-btn-warm" onclick="openPdf( 'insurancePdf');" style="display: inline">查看PDF</button>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">医保号</label>
			<div class="layui-input-block">
				<input type="text" name="insuranceNo" required placeholder="请输入医保号" class="layui-input">
			</div>
		</div>
	</div>
</form>

<form id="agreement_company" class="layui-form layui-row layui-col-space10 register-agreement-form dn" onkeydown="if(event.keyCode==13) return false;">
	<div class="layui-col-md12 layui-col-xs12">
		<div class="layui-form-item">
			<label class="layui-form-label">公司名称</label>
			<div class="layui-input-block">
				<input type="text" name="companyName" required placeholder="请输入公司名称" class="layui-input">
			</div>
		</div>

		<input name="id" id="companyId" type="hidden"/>

		<div class="layui-form-item">
			<label class="layui-form-label">公司地址</label>
			<div class="layui-input-block">
				<input type="text" name="companyAddress" required placeholder="请输入公司地址" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">邮编</label>
			<div class="layui-input-block">
				<input type="text" name="emailCode" required  placeholder="请输入邮编" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">公司证明</label>
			<div class="layui-input-block">
				<button type="button" class="layui-btn layui-btn-sm" id="certificatePdfBtn" style="display: inline">
					<i class="layui-icon">&#xe67c;</i>上传公司证明PDF
				</button>
				<input type="text" name="certificatePdf" required readonly class="layui-input" style="display: inline;width: 400px;">
				<button type="button" class="layui-btn layui-btn-sm layui-btn-warm" onclick="openPdf( 'certificatePdf');" style="display: inline">查看PDF</button>
				<a> </a>
			</div>
		</div>
	</div>
</form>

<form id="agreement_visitor" class="layui-form layui-row layui-col-space10 register-agreement-form dn" onkeydown="if(event.keyCode==13) return false;">
	<div class="layui-col-md12 layui-col-xs12">
		<div class="layui-form-item">
			<label class="layui-form-label">生日</label>
			<div class="layui-input-block">
				<input type="text" name="birthDay" placeholder="请输入出生年月" required readonly class="layui-input userBirthday">
			</div>
		</div>

		<input name="id" id="visitorId" type="hidden"/>

		<div class="layui-form-item">
			<label class="layui-form-label">护照复印件</label>
			<div class="layui-input-block">
				<button type="button" class="layui-btn layui-btn-sm" id="passportPdfBtn" style="display: inline">
					<i class="layui-icon">&#xe67c;</i>上传护照复印件PDF
				</button>
				<input type="text" name="passportPdf" required readonly class="layui-input" style="display: inline;width: 400px;">
				<button type="button" class="layui-btn layui-btn-sm layui-btn-warm" onclick="openPdf( 'passportPdf');" style="display: inline">查看PDF</button>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">护照号</label>
			<div class="layui-input-block">
				<input type="text" name="passportNo" required placeholder="请输入护照号" class="layui-input">
			</div>
		</div>
	</div>
</form>

<form class="layui-form layui-row layui-col-space10 register-baseInfo-form" onkeydown="if(event.keyCode==13) return false;">
	<div class="layui-col-md12 layui-col-xs12">
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="button" class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
			</div>
		</div>
	</div>
</form>
</body>

<script type="text/javascript">

	//新窗口打开pdf文件
	function openPdf( pdfName) {
		var pdfUrl = $("input[name=" + pdfName + "]").val();
		window.open( pdfUrl, "_blank");
	}

	layui.use(['form','layer','jquery','upload','laydate'],function(){
		var form = layui.form,
				layer = parent.layer === undefined ? layui.layer : top.layer
		$ = layui.jquery,
				laydate = layui.laydate,
				upload = layui.upload;

		//选择出生日期
		laydate.render({
			elem: '.userBirthday',
			format: 'yyyy年MM月dd日',
			trigger: 'click',
			max : 0,
			done: function(value, date){

			}
		});
		//居留复印件 pdf 上传
		upload.render({
			elem: '#residencePdfBtn',
			url: '/file/upload?type=residencePdf',
			method : "post",
			accept: "file",
			exts: "pdf",
			done: function(res, index, upload){ //上传后的回调
				$("input[name=residencePdf]").val( res.data.filePath);
			}
		});
		//居留复印件 pdf 上传
		upload.render({
			elem: '#insurancePdfBtn',
			url: '/file/upload?type=insurancePdf',
			method : "post",
			accept: "file",
			exts: "pdf",
			done: function(res, index, upload){ //上传后的回调
				$("input[name=insurancePdf]").val( res.data.filePath);
			}
		});
		//公司证明 pdf 上传
		upload.render({
			elem: '#certificatePdfBtn',
			url: '/file/upload?type=certificatePdf',
			method : "post",
			accept: "file",
			exts: "pdf",
			done: function(res, index, upload){ //上传后的回调
				$("input[name=certificatePdf]").val( res.data.filePath);
			}
		});
		//护照证明 pdf 上传
		upload.render({
			elem: '#passportPdfBtn',
			url: '/file/upload?type=passportPdf',
			method : "post",
			accept: "file",
			exts: "pdf",
			done: function(res, index, upload){ //上传后的回调
				$("input[name=passportPdf]").val( res.data.filePath);
			}
		});

		var agreementType = getUrlParamer( "agreementType");
		var agreementId = getUrlParamer( "agreementId");
		var readonly = getUrlParamer( "readonly");
		if( readonly == "true"){
			readonly = true;
		}else{
			readonly = false;
		}
		//加载表单数据
		$.post("/agreement/getAgreement",{
			'agreementId': agreementId,
			'agreementType': agreementType
		},function( res){
			if( res.code == 200){
				var formData = res.data;
				switch ( agreementType) {
					case "1" :
						$("#trialId").val( agreementId);
						$("input[name=birthDay]").val( formData.birthDay).attr( "readonly", readonly);;
						$("input[name=receiver]").val( formData.receiver).attr( "readonly", readonly);;
						$("input[name=address]").val( formData.address).attr( "readonly", readonly);;
						$("input[name=emailCode]").val( formData.emailCode).attr( "readonly", readonly);;
						$("input[name=residencePdf]").val( formData.residencePdf).attr( "readonly", readonly);;
						$("input[name=residenceNo]").val( formData.residenceNo).attr( "readonly", readonly);;
						$("input[name=insurancePdf]").val( formData.insurancePdf).attr( "readonly", readonly);;
						$("input[name=insuranceNo]").val( formData.insuranceNo).attr( "readonly", readonly);;
						$("#agreement_trial").removeClass( "dn");
						break;
					case "2" :
						$("#visitorId").val( agreementId);
						$("input[name=birthDay]").val( formData.birthDay).attr( "readonly", readonly);;
						$("input[name=receiver]").val( formData.receiver).attr( "readonly", readonly);;
						$("input[name=address]").val( formData.address).attr( "readonly", readonly);;
						$("input[name=emailCode]").val( formData.emailCode).attr( "readonly", readonly);;
						$("input[name=residencePdf]").val( formData.residencePdf).attr( "readonly", readonly);;
						$("input[name=residenceNo]").val( formData.residenceNo).attr( "readonly", readonly);;
						$("input[name=insurancePdf]").val( formData.insurancePdf).attr( "readonly", readonly);;
						$("input[name=insuranceNo]").val( formData.insuranceNo).attr( "readonly", readonly);;
						$("#agreement_trial").removeClass( "dn");
					break;
					case "3" :
						$("#companyId").val( agreementId);
						$("input[name=companyName]").val( formData.companyName).attr( "readonly", readonly);;
						$("input[name=companyAddress]").val( formData.companyAddress).attr( "readonly", readonly);;
						$("input[name=emailCode]").val( formData.emailCode).attr( "readonly", readonly);;
						$("input[name=certificatePdf]").val( formData.certificatePdf).attr( "readonly", readonly);;
						$("#agreement_company").removeClass( "dn");
						break;
					case "4" :
						$("#visitorId").val( agreementId);
						$("input[name=birthDay]").val( formData.birthDay).attr( "readonly", readonly);;
						$("input[name=passportPdf]").val( formData.passportPdf).attr( "readonly", readonly);;
						$("input[name=passportNo]").val( formData.passportNo).attr( "readonly", readonly);;
						$("#agreement_visitor").removeClass( "dn");
						break;
				}
			}else{
				top.layer.alert( res.msg);
			}
		});

		//提交注册表单按钮
		form.on("submit(submit)",function(){
			//先提交合同表单
			//根据合同类型提交对应的表单，提交接口返回合同数据的id
			var saveAgreementUrl;
			var agreementJson;

			switch ( agreementType) {
				case "1" :
					saveAgreementUrl = "/agreement/saveTrial";
					agreementJson = $("#agreement_trial").serialize();
					break;
				case "2" :
					saveAgreementUrl = "/agreement/saveTrial";
					agreementJson = $("#agreement_trial").serialize();
					break;
				case "3" :
					saveAgreementUrl = "/agreement/saveCompany";
					agreementJson = $("#agreement_company").serialize();
					break;
				case "4" :
					saveAgreementUrl = "/agreement/saveVisitor";
					agreementJson = $("#agreement_visitor").serialize();
					break;
			}

			$.post( saveAgreementUrl, agreementJson , function( res){
				if( res.code == 200){
					setTimeout(function(){
						top.layer.msg( "修改成功");
						layer.closeAll( "iframe");
					},500);
				}else{
					top.layer.alert( res.msg);
				}
			});
		});
	});
</script>
</html>
